package com.yequan.sourcecode.javautil;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author : Administrator
 * @date : 2020/3/21
 */
public class DequeDemo {

    public static void main(String[] args) {
        DequeDemo dequeDemo = new DequeDemo();

//        dequeDemo.oldQueueApi();
//        dequeDemo.newDequeApi1();
//        dequeDemo.newDequeApi2();
        dequeDemo.newDequeApi3();

    }

    private void newDequeApi3() {
        Deque<String> deque = new LinkedList<>();
        deque.offerFirst("春");
        deque.offerLast("夏");
        deque.offerFirst("秋");

        System.out.println(deque);
    }

    private void newDequeApi2() {
        Deque<String> deque = new LinkedList<>();
        deque.offerFirst("甲");
        deque.offerFirst("乙");
        deque.offerFirst("丙");
        //查看原始队列
        System.out.println(deque);

        //查看顶部
        System.out.println(deque.peekFirst());
        System.out.println(deque);

        //出队列
        while (deque.size()>0){
            System.out.println(deque.pollFirst());
        }
        System.out.println(deque);
    }

    private void newDequeApi1() {
        Deque<String> deque = new LinkedList<>();
        deque.addFirst("a");
        deque.addFirst("b");
        deque.addFirst("c");
        //查看原始队列
        System.out.println(deque);

        //查看最顶部
        System.out.println(deque.getFirst());
        System.out.println(deque);

        //出队列
        while (deque.size() > 0) {
            System.out.println(deque.removeFirst());
        }
        System.out.println(deque);
    }

    private void oldQueueApi() {
        Deque<String> deque = new LinkedList<>();
        deque.push("1");
        deque.push("2");
        deque.push("3");

        //原始队列
        System.out.println(deque);

        //查看最顶部
        String peek = deque.peek();
        System.out.println(peek);
        System.out.println(deque);

        //出队列
        while (deque.size() > 0) {
            System.out.println(deque.pop());
        }
        System.out.println(deque);
    }


}
